<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <title>Document</title>
    </head>
    <body>
        <script>
            let user1 = {
                name: "xuhu",
                age: 23,
            };
            let user2 = {
                name: "xuyawen",
            };
            // 通过Object.defineProperty对user2的age属性实现数据代理
            Object.defineProperty(user2, "age", {
                get() {
                    // 返回user1的age
                    return user1.age;
                },
                set(value) {
                    // 当user2的age属性发生变化的时候，更改user1的age
                    user1.age = value;
                },
            });
        </script>
    </body>
</html>
